package com.cloudkinto.service.order.outbound;

import com.baomidou.mybatisplus.extension.service.IService;
import com.cloudkinto.bo.api.TransferSendApiBo;
import com.cloudkinto.bo.order.outbound.*;
import com.cloudkinto.common.exception.BizException;
import com.cloudkinto.common.web.PageResult;
import com.cloudkinto.common.web.SingleResult;
import com.cloudkinto.entity.OrderOutboundDo;
import com.cloudkinto.entity.OrderOutboundPackageDo;
import com.cloudkinto.entity.OutboundPickingDo;
import com.cloudkinto.entity.ProductStockRackDo;
import com.cloudkinto.enumType.order.outbound.OutboundOriginEnum;
import com.cloudkinto.service.event.order.OrderSubcontractEvent;
import com.cloudkinto.vo.api.TransferOutboundApiVo;
import com.cloudkinto.vo.common.CommonBatchOperationVo;
import com.cloudkinto.vo.order.outbound.*;
import com.cloudkinto.vo.wr.cost.OrderOutCostReq;
import com.cloudkinto.vo.wr.trial.TrialOmsReq;
import org.springframework.validation.annotation.Validated;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * <p>
 * 出库单 service接口
 * </p>
 *
 * @author long
 * @since 2024-11-21
 */
public interface OutboundService extends IService<OrderOutboundDo> {

    void pushToJdCloud();

    void consumerPushToJdCloud(List<OrderOutboundDo> list);

    void getJdyTrackNumber();

    void getJdyTrackNumberManual(List<String> platformOrders);

    void consumerGetJdyTrackNumber(List<OrderOutboundDo> list);

    List<String> consumerJdyOutboundAutoSendByNo(List<String> outboundNoList, int orderType, Long whId, Long userId, String username);

    List<String> consumerJdyOutboundAutoSend(List<Long> outBoundIds, int orderType, Long whId, Long userId, String username);

    void autoSendOutboundHandler(Collection<OrderOutboundDo> outboundList, Long userId, String username);

    void dealError(List<Long> outBoundIds, Long whId);

    void postOutboundOperation(OrderOutboundDo outboundDo, List<OutboundPickingDo> noPickingListByOutboundId);

    Long normalSave(NormalOrderOutboundSaveBo bo, Long userId, String username, Long companyId, Long tenantId, OutboundOriginEnum origin) throws BizException;

    void transferSave(TransferOrderOutboundSaveBo bo, Long userId, String username, Long tenantId, Long companyId) throws BizException;

    int normalUpdate(NormalOutboundUpdateBo updateVo, Long userId, String username);

    void delete(Long id, Long userId);

    NormalOutboundDetail normalOutboundDetail(Long id, Long userId, String source);

    TransferOutboundDetail transferOutboundDetail(Long id, Long userId, String source);

    SingleResult<Map<String, Object>> pageInit(Long userId, Long tenantId, Long companyId, String source);

    PageResult<NormalOutboundVo> getNormalListPageApi(NormalOrderOutboundQueryBo bo);


    PageResult<NormalOutboundVo> getNormalListPage(NormalOrderOutboundQueryBo bo);

    SingleResult getNormalStatusSta(NormalOrderOutboundQueryBo bo);

    PageResult<TransferOutboundApiVo> getTransferListPageApi(TransferOrderOutboundQueryBo bo);

    PageResult<TransferOutboundVo> getTransferListPage(TransferOrderOutboundQueryBo bo);

    SingleResult getTransferStatusSta(TransferOrderOutboundQueryBo bo);

    SingleResult transferSubmitPick(List<Long> ids, Long userId, String username);

    TransferOutboundPickingDetail transferPickingDetail(Long id);

    Map<String, Object> transferPickingDetailInit(Long userId, Long tenantId, String source);

    boolean transferPicking(TransferOutboundPickingBo bo, Long userId, String username, Long tenantId);

    List<TransferPickingByBatchDetail> transferPickingDetailBatch(List<Long> ids);

    List<Long> transferPickingBatch(TransferPickingBatchBo bo, Long userId, String username, Long tenantId);

    OutboundPreOperationVo transferOutboundPreOperation(List<Long> ids);

    SingleResult transferOutboundOperationBatch(List<Long> ids, Long userId, String username);

    SingleResult transferOutboundOperation(TransferOutboundOperationBo bo, Long userId, String username);

    TransferOutboundPackDetail transferOutboundPackDetail(Long id);

    SingleResult transferOutboundPack(TransferOutboundPackBo bo, Long userId, String username);

    SingleResult normalCreateWave(NormalOutboundCreateWaveBo bo, Long userId, String username);

    SingleResult normalWeighDetail(String scan);

    SingleResult weigh(NormalWeighBo bo, Long userId, String username, Long whId);

    SingleResult normalQuickOutbound(List<Long> ids, Long userId, String username);

    SingleResult normalOutboundOperate(List<Long> ids, Long userId, String username);

    SingleResult markException(Long id, Long userId, String username);

    PageResult exceptionOrderPageList(ExceptionOutboundQueryBo bo);

    SingleResult removeException(Long id, Long userId, String username);

    SingleResult exceptionConfirm(ExceptionConfirmBo bo, Long userId, String username);

    /**
     * 根据出库单对象构建出库计费实体
     *
     * @param outboundDo 出库单
     * @param status     0实扣 1预扣
     * @return 出库单计算操作费bo
     */
    OrderOutCostReq buildOutboundCostReq(OrderOutboundDo outboundDo, Integer status);

    /**
     * 构建运费试算req
     *
     * @param entityDo 出库单实体
     */
    TrialOmsReq buildTrialFreightReq(OrderOutboundDo entityDo);

    void createTransferProgress(OrderOutboundDo entityDo, String username);

    String generateOutboundNo(String orderType);

    void lockStockAndSavePicking(
            List<ProductStockRackDo> productStockRackDoList,
            AtomicInteger needLock,
            String productIdOrBoxTypeNumber,
            Long outboundProductId,
            Boolean pickFlag) throws BizException;

    void createNormalProgress(OrderOutboundDo entityDo, String username);

    SingleResult uploadAttachment(OutboundUploadAttachmentBo bo, Long userId, String username);

    SingleResult getPickerList(Long tenantId);

    SingleResult assignLogistics(AssignLogisticsBo bo, Long userId, String username);

    CommonBatchOperationVo submitDraft(OutboundSubmitDraftBo bo, Long tenantId, Long userId, String username);

    CommonBatchOperationVo turnIntoDraft(OutboundTurnIntoDraftBo bo, Long userId, String username);

    CommonBatchOperationVo cancel(OutboundCancelBo bo, Long userId, String username, Long companyId);

    void dealPackageDetail(OrderSubcontractEvent event);

    OrderOutboundPackageDo calculatePackageSize(Long outboundId, Integer serialNumber, String trackingNumber, Long labelFileId, List<PackageSizeVo> packageSizeVoList, boolean save);

    void unLock(List<OutboundPickingDo> unLockPickingList, List<OutboundPickingDo> noPickingDoList, AtomicInteger needUnlock);

    /**
     * 扣减库存
     */
    boolean deductionOfInventory(@Validated DeductionOfInventoryBo bo);

    CommonBatchOperationVo batchUpdateWhAndChannel(OutboundBatchUpdateWhAndChannelBo bo, Long userId, String username, Long companyId);

    String getJdyToken() throws Exception;

    SingleResult postToJdy(String jdyToken, String jdyUrl, Object data) throws Exception;

    List<String> batchUpdateStatus(List<String> outboundNoList, Integer status, int orderType, Long whId, Long userId, String username);

    List<String> exceptionOrder(List<String> outboundNoList, String exceptionType, String exceptionReason, int orderType, Long whId, Long userId);

    SingleResult transferOutboundOperationApi(TransferSendApiBo bo, Long userId, String username);

    SingleResult outboundUpdateChannelAndTrackingNo(OutboundUpdateChannelAndTrackingNoBo bo, Long userId, String username);
}
